package com.jae.controller.user;

import com.jae.controller.BaseController;
import com.jae.model.ResultMsg;
import com.jae.model.ServiceRuntimeException;
import com.jae.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/open/user")
public class UserOpenController extends BaseController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResultMsg login(String username, String password, HttpServletRequest request) {
        String interfaceName = "用户登录";
        try {
            return new ResultMsg(true, userService.login(username, password,"token"));
        } catch (ServiceRuntimeException e) {
            return fail(e);
        } catch (Exception e) {
            return error(interfaceName, e, request);
        }
    }
}
